import { systemCreateSchema } from "~/validators/system";
export default defineEventHandler(async (event) => {
  const result = await runValidate(systemCreateSchema, event);

  const { name } = result.data;
  const system = await SystemSchema.findOne({ name: name }).lean();
  if (system) {
    throw createError({
      statusCode: 409,
      statusMessage: "系统配置已存在，请修改后重试",
    });
  }

  const newData = await SystemSchema.create(result.data);
  return newData;
});
